import { getMasterCommonPkg } from '@/utils/masterData';

const {
  request,
  consts: {
    environment: { apiUrl, commonPrefix, servePrefix },
  },
} = getMasterCommonPkg();

// 申请查询
export async function approvalSearch(data) {
  const { pageSize, pageNum, businessType, status } = data;
  return request(
    `${commonPrefix}/v1/apply/list/${pageSize}/${pageNum}`,
    {
      method: 'GET',
      params: {
        businessType,
        status,
      },
    },
    apiUrl,
  );
}

// 申请添加
export async function approvalAdd(data) {
  return request(
    `${commonPrefix}/v1/apply`,
    {
      method: 'POST',
      body: JSON.stringify(data),
    },
    apiUrl,
  );
}

// 申请同意

// 申请删除
export async function approvalDel(data) {
  const { id } = data;
  return request(
    `${commonPrefix}/v1/apply/${id}`,
    {
      method: 'DELETE',
    },
    apiUrl,
  );
}

// API- 查看申请详情
export async function APIDetail(data) {
  const { id } = data;
  return request(
    `${commonPrefix}/v1/apply/detail/${id}`,
    {
      method: 'GET',
      params: {},
    },
    apiUrl,
  );
}

// 获取树形结构菜单
export async function getDirectoryTree(data) {
  console.log(data);
  return request(
    `${servePrefix}/v1/group/tree/${data}/${data}`,
    {
      method: 'GET',
      params: data.params,
    },
    apiUrl,
  );
}

// 申请同意

export async function approvalAgree(data) {
  let { id } = data;
  return request(
    `${commonPrefix}/v1/apply/${id}`,
    {
      method: 'PUT',
    },
    apiUrl,
  );
}

// 申请拒绝

export async function approvalReject(data) {
  return request(
    `${commonPrefix}/v1/apply/reject`,
    {
      method: 'PUT',
      body: JSON.stringify(data),
    },
    apiUrl,
  );
}

/* 我的权限*/

// 数据源权限申请
export async function applyPower(data) {
  return request(
    `${commonPrefix}/v1/apply`,
    {
      method: 'POST',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

//数据类型查询
export async function getDataType() {
  return request(
    `${commonPrefix}/v1/dataSource/allList`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

// 我的权限 --数据源
export async function getdataSoure(data) {
  return request(
    `${commonPrefix}/v1/apply/dataSource/list/${data.params.pageSize}/${data.params.pageNum}`,
    {
      method: 'GET',
      params: data.params.name,
    },
    apiUrl,
  );
}
// 我的权限 --api数据
export async function getApiSoure(data) {
  return request(
    `${commonPrefix}/v1/apply/api/list/${data.params.pageSize}/${data.params.pageNum}`,
    {
      method: 'GET',
      params: data.params.name,
    },
    apiUrl,
  );
}

// 数据源查看详情
export async function getDataDetail(data) {
  return request(
    `${commonPrefix}/v1/dataSource/detail/${data.params}`,
    {
      method: 'GET',
      params: data.params,
    },
    apiUrl,
  );
}

// 数据源测试连接

export async function getDataTest(data) {
  return request(
    `${commonPrefix}/v1/dataSource/test/${data.params}`,
    {
      method: 'GET',
      params: data.params,
    },
    apiUrl,
  );
}

// 工作空间查询 成员列表查询

export async function getMemberList() {
  return request(
    `${commonPrefix}/v1/workspace/user/workspace`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

// 空间成员列表详情
export async function getMemberListDetail(data) {
  return request(
    `${commonPrefix}/v1/workspace/detail/${data.params.id}`,
    {
      method: 'GET',
      params: data.params,
    },
    apiUrl,
  );
}

// 空间成员列表 添加成员
export async function addWorkspaceUser(data) {
  return request(
    `${commonPrefix}/v1/workspace/users`,
    {
      method: 'POST',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

// 空间成员删除
export async function deleteWorkspaceUser(data) {
  return request(
    `${commonPrefix}/v1/workspace/users`,
    {
      method: 'DELETE',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

// 工作空间删除
export async function workSpaceDelete(data) {
  return request(
    `${commonPrefix}/v1/workspace/id/${data.params.id}`,
    {
      method: 'DELETE',
    },
    apiUrl,
  );
}

// 工作空间详情 -- 查询name

export async function WorkSpaceName(data) {
  return request(
    `${commonPrefix}/v1/workspace/detail/${data.id}`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

export default {
  approvalSearch,
  approvalAdd,
  approvalDel,
  APIDetail,
  approvalAgree,
  approvalReject,
  getDirectoryTree,
  WorkSpaceName,
};
